

local mt = ac.skill['亡魂攻击']
mt.skill_type = "passive"
mt.model1 = [[Abilities\Weapons\ZigguratFrostMissile\ZigguratFrostMissile.mdl]]

function mt:on_add()
    local hero = self.owner
    
    self.effect = hero:get_point():add_effect([[range_circle.mdl]])
    self.effect:set_scale(hero:get('攻击距离') / (512 - hero:get_collision()))
    self.effect:set_color(100,0,0)
    self.effect:set_visible(false)
    self:gc(self.effect)
    self:gc(hero:event '单位-攻击'(function(_,_,target)
        if target:is_type('英雄') then
            target:add_buff '显示伤害范围'{effect = self.effect}
        end
    end))

    self:gc(hero:event '单位-攻击出手'(function(_,source,target)
        local start = source:get_launch_point()
        local point = target:get_point()
        if start*point>hero:get('攻击距离') then
            return true
        end
        local area = 70
        local effect = ac.hint_red(point,area,99)
        ac.mover('point'){
            target = point,
            start = start,
            model = self.model1,
            speed = 900,
            on_remove = function()
                effect:remove()
                if hero:is_alive() then
                    source:aoe_damage(point,area,nil,'普攻')
                end
            end,
        }
        return true
    end))
end



local buff = ac.buff['显示伤害范围']
buff.time = 2
buff.cover_type = 1
buff.cover_max = 0

function buff:on_add()
    local hero = self.owner
    local player = hero.owner
    local effect = self.effect
    if player:is_self() then
        effect.show_count = (effect.show_count or 0) + 1
        effect:set_visible(true)
    end
    self:gc(function()
        if player:is_self() then
            effect.show_count = (effect.show_count or 0) - 1
            if effect.show_count<=0 then
                effect:set_visible(false)
            end
        end
    end)
end